<?php
/**
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT		: Rubik Ultimate Framework
 * @version 	: 1.1
 * COPYRIGHT    : 2008
 * ------------------------------------------------------
 * 
 * Created on	:  Jun 17, 2008
 * 
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );

define ( "SCRIPT_TEXT_CONTENT", 0 );
define ( "SCRIPT_FILE_CONTENT", 1 );

define ( "SCRIPT_TYPE_JS", 0 );
define ( "SCRIPT_TYPE_CSS", 1 );

define ( "SCRIPT_MEDIA_PRINT", "print" );
define ( "SCRIPT_MEDIA_SCREEN", "screen" );

/**
 * Class for holding the content of javascript
 *
 */
class ScriptContent extends Object {
	var $content;
	var $scriptType;
	var $contentType;
	var $media;
	
	/**
	 * Constructor
	 *
	 * @param string $content
	 * @param script_type $scriptType  SCRIPT_TYPE_JS/SCRIPT_TYPE_CSS
	 * @param content_type $contentType  SCRIPT_TEXT_CONTENT/SCRIPT_FILE_CONTENT
	 * @param string $media the media name of this script
	 */
	function __construct($content, $scriptType, $contentType, $media = null) {
		$this->content = $content;
		$this->scriptType = $scriptType;
		$this->contentType = $contentType;
		$this->media = $media;
	}
	
	/**
	 * Get the HTML of this script.
	 *
	 * @return string
	 */
	function getHtml() {
		if (empty ( $this->media )) {
			$media = "";
		} else {
			$media = " media=\"{$this->media}\"";
		}
		if ($this->scriptType === SCRIPT_TYPE_JS) {
			if ($this->contentType == SCRIPT_FILE_CONTENT) {
				return "<script type=\"text/javascript\" src=\"{$this->content}\" $media></script>\r\n";
			}
			return "<script type=\"text/javascript\" $media>\r\n// <![CDATA[\r\n{$this->content}\r\n// ]]>\r\n</script>\r\n";
		}
		if ($this->contentType == SCRIPT_FILE_CONTENT) {
			return "<link type=\"text/css\" href=\"{$this->content}\" rel=\"stylesheet\" $media />\r\n";
		}
		return "<style type=\"text/css\" $media>\r\n{$this->content}\r\n</style>\r\n";
	}
	
	/**
	 * Echo the HTML of this script.
	 *
	 */
	function printHtml() {
		echo $this->getHtml ();
	}
}
?>